* (bug 5062) Width sometimes one pixel short when using maximum heights
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2
3 if( php_sapi_name() != 'cli' ) {
4 echo 'Must be run from the command line.';
5 die( -1 );
6 }
7
8 error_reporting( E_ALL );
9 define( "MEDIAWIKI", true );
10
11 set_include_path( get_include_path() . PATH_SEPARATOR . 'PHPUnit' );
12 set_include_path( get_include_path() . PATH_SEPARATOR . '..' );
13 require_once( 'PHPUnit.php' );
14
15 $testOptions = array(
16 'mysql4' => array(
17 'server' => null,
18 'user' => null,
19 'password' => null,
20 'database' => null ),
21 'postgresql' => array(
22 'server' => null,
23 'user' => null,
24 'password' => null,
25 'database' => null ),
26 );
27
28 if( file_exists( 'LocalTestSettings.php' ) ) {
29 include( './LocalTestSettings.php' );
30 }
31
32 $tests = array(
33 'GlobalTest',
34 'DatabaseTest',
35 'SearchMySQL4Test',
36 'ArticleTest',
37 'SanitizerTest',
38 'CtypeTest',
39 'ImageTest'
40 );
41
42 if( isset( $_SERVER['argv'][1] ) ) {
43 // to override...
44 $tests = array( $_SERVER['argv'][1] );
45 }
46
47 foreach( $tests as $test ) {
48 require_once( $test . '.php' );
49 $suite = new PHPUnit_TestSuite( $test );
50 $result = PHPUnit::run( $suite );
51 echo $result->toString();
52 }
53
54 /**
55 * @param string $serverType
56 * @param array $tables
57 */
58 function &buildTestDatabase( $serverType, $tables ) {
59 global $testOptions, $wgDBprefix;
60 $wgDBprefix = 'parsertest';
61 $db =& new Database(
62 $testOptions[$serverType]['server'],
63 $testOptions[$serverType]['user'],
64 $testOptions[$serverType]['password'],
65 $testOptions[$serverType]['database'] );
66 if( $db->isOpen() ) {
67 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
68 # Database that supports CREATE TABLE ... LIKE
69 foreach ($tables as $tbl) {
70 $newTableName = $db->tableName( $tbl );
71 #$tableName = $this->oldTableNames[$tbl];
72 $tableName = $tbl;
73 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
74 }
75 } else {
76 # Hack for MySQL versions < 4.1, which don't support
77 # "CREATE TABLE ... LIKE". Note that
78 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
79 # would not create the indexes we need....
80 foreach ($tables as $tbl) {
81 $res = $db->query("SHOW CREATE TABLE $tbl");
82 $row = $db->fetchRow($res);
83 $create = $row[1];
84 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
85 . $wgDBprefix . '\\1`', $create);
86 if ($create === $create_tmp) {
87 # Couldn't do replacement
88 wfDie( "could not create temporary table $tbl" );
89 }
90 $db->query($create_tmp);
91 }
92
93 }
94 return $db;
95 } else {
96 // Something amiss
97 return null;
98 }
99 }
100
101 ?>